<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
  <head>
    <base href="<%=basePath%>">  
    <title>阶乘运算</title>
  </head>
  <%!
      public int Factorial(int num){
      	int s=1;
      	if(num==0){
      		s=0;
      	}else{
  			for(int i=1;i<=num;i++)
  				s*=i;	
  		}	
  		return s;
  	  }
  %>
  <%
   	int num=0;
   	String str=request.getParameter("num");
   	try{
   		if(str!=null)
   			num=Integer.parseInt(str);
   	}catch(Exception e){
   		out.println("只能输入整数");
   	}
    %>    
  <body>
   <p>请输入一个整数：</p>
   <form action="jieCheng.jsp" method="" name="form">
   		<input type="text" name="num">
   		<input type="submit" name="submit" value="开始计算">
   </form>     
 	 <p><%=num%>的阶乘是：<%=Factorial(num)%></p>
  </body>
</html>





















